remotemanager.script.script module¶
This module holds the Script class, which handles the generation and parameterization of scripts.
- class remotemanager.script.script.EscapeStub(content: Any)[source]¶
Stub class for avoiding regex’s internal escape sequence handling
If the repl argument of re.sub is a callable, escape sequences will not be processed, allowing us to handle them at a later stage.
This is important for allowing templates to escape the : character
- class remotemanager.script.script.Script(template: str | None = None, template_path: str | None = None, empty_treatment: str | None = None, header_only: bool = False, **init_args)[source]¶
Class for a generic, parameterisable script.
- Parameters:
template (str) – Base script to use. Accepts #parameters#
- property uuid: str¶
return the uuid of this script
- property short_uuid: str¶
return the shortened uuid of this script
- property template: str¶
Returns the template
- property subs: list[str]¶
Returns a list of all substitution names
- property sub_objects: list[Substitution]¶
Returns a list of all substitution objects
- property args: list¶
Alias for self.subs
- property arguments¶
Alias for self.subs
- property required: list[str]¶
Returns a list of all required values
- Returns:
a list of all required values
- Return type:
list[str]
- property missing: list[str]¶
Returns a list of all missing required values
- Returns:
a list of all missing required values
- Return type:
list[str]
- property valid: bool¶
Returns True if the script is currently “valid”
Validation is defined as having no missing required values and all required values being present.
- ..note::
Note that this property only considers values that have been flagged as required in the template. This essentially makes it up to the user to enable this functionality in their templates.
- Returns:
True if the script is currently “valid”
- Return type:
bool
- property empty_treatment: str | None¶
Returns the currently set global behaviour for empty treatment.
- property header_only: bool¶
Toplevel flag to dictate whether we should return the whole script or just the header
- script(empty_treatment: str | None = None, header_only: bool | None = None, **run_args: Any) str [source]¶
Generate the script
- Parameters:
empty_treatment (str, None) – Overrides any local setting of
empty_treatment
if not Noneheader_only (bool) – If True, attempt to only return the resource request header
- Returns:
the formatted script
- Return type:
str
- extract_header() str [source]¶
Attempt to extract the resource header from the template.
Here, we assume that the resource header is marked by some #PRAGMA, which is either the top of the file or follows a shebang
We must do this on the template, instead of the output, to make it more deterministic. Though we must not modify the template, since that could brick the script generation. Best we can do is generate the “header only” template, then also perform the same replacements on that before returning that.
- pack(values: bool = True, file: str | None = None) str [source]¶
Store the Script
- Parameters:
values (bool) – includes any set values if True
file (str) – path to save to, returns the content if None
- Returns:
File path if file is not None, else the storage content
- Return type:
str
- classmethod unpack(input: str)[source]¶
Re-create an object from a packaged payload coming from
obj.pack
Note
use this function to unpack from a payload _outside_ an object
newobj = MyObject.unpack(payload)
Where
MyObject
is a subclass of SendableMixin, andpayload
is a dict-type coming fromMyObject.pack()
- Parameters:
data (dict) – __dict__ payload from the object that was packaged
file (str) – filepath to unpack from, if data is not given
limit (bool) – set False to allow outside classes to be unserialised
- Returns:
re-created object